home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
UTILITIE
/
UNIX_COH
/
2774A.ZIP
/
UPTIME.CZ
/
UPTIME
Wrap
Text File
|
1991-07-02
|
1KB
|
59 lines
#include <stdio.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
/************************************************************************
UPTIME - by Mark J. Quarles
This little program will report the elapsed time since the last
boot of your system.
It does it by getting the "last modify" time for the file
/etc/boottime, and then calculating the difference between that time and
the current time. The output is in the form of hh:mm:ss elapsed since the
last boot of the system.
************************************************************************/
main()
{
long delta,current_time;
int hours,minutes,seconds;
struct stat statptr;
/*
* Get the time of last modification of the /etc/boottime file, which is
* created each time the system boots.
*/
if (stat("/etc/boottime",&statptr)==-1) {
printf("%cError: STAT call error\n",7);
exit(1);
}
time(¤t_time); /* get the current time */
printf("\nLast system boot was %s\n",ctime(&statptr.st_mtime));
delta=current_time-statptr.st_mtime; /* calculate the delta time */
/*
* Now, just convert the elapsed seconds since boot into hours/min/sec
* format
*/
hours=delta/3600;
delta-=(hours*3600L);
minutes=delta/60;
delta -= minutes*60L;
seconds=delta;
printf("System uptime is %02.2d:%02.2d:%02.2d\n\n",hours,minutes,seconds);
}